<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .content {
      width: 200px;
      height: 200px;
      border: 1px solid #333;
      font-size: 40px;
      text-align: center;
      line-height: 200px;
      display: none;
    }

    button.active {
      background-color: rgb(180, 169, 48);
    }
  </style>
</head>

<body>
  <button class="active">标题1</button>
  <button>标题2</button>
  <button>标题3</button>
  <div class="content" style="display: block">内容1</div>
  <div class="content">内容2</div>
  <div class="content">内容3</div>
  <script>
    var btns = document.querySelectorAll('button');
    var content = document.querySelectorAll('.content');
    for (var i = 0; i < btns.length; i++) {
      btns[i].index = i;
      btns[i].onclick = function() {
        for (var i = 0; i < btns.length; i++) {
          btns[i].classList.remove('active');
          content[i].style.display = 'none';
        }
        this.classList.add('active');
        content[this.index].style.display = "block";
      }
    }
  </script>
</body>

</html>